<!--
  #%L
  thinkbig-ui-operations-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->
<card-layout header-css="filter-header">
    <header-section>
        <tba-card-filter-header transclude-to="head" flex layout card-title="vm.cardTitle" page-name="{{vm.pageName}}" view-type="vm.viewType" sort-options="vm.sortOptions"
            additional-options="vm.additionalMenuOptions"
            on-selected-additional-option="vm.selectedAdditionalMenuOption"
            on-selected-option="vm.selectedTableOption"
            card-controller="vm"
            custom-filter-template="js/ops-mgr/alerts/alert-type-filter-select.html"
            filter-model="vm.filter"
            filter-model-options="{debounce:1000}">
        </tba-card-filter-header>

    </header-section>
    <body-section transclude-to="body">
        <md-tabs flex md-selected="vm.tabMetadata.selectedIndex" md-align-tabs="top" layout-fill md-dynamic-height>

            <md-tab ng-repeat="tab in vm.tabs" ng-disabled="tab.disabled" md-on-select="vm.onTabSelected(tab)" flex>
                <md-tab-label>{{tab.title}}</md-tab-label>
                <md-tab-body>
                    <md-divider></md-divider>
                    <div ng-show="vm.viewType == 'list'">
                        <div ng-if="vm.showProgress" class="md-list-table-progress">
                            <md-progress-linear class="md-accent" md-mode="indeterminate"></md-progress-linear>
                            <br/><br/>
                        </div>
                        <md-list flex layout-fill ng-show="vm.loading == false" class="list-item-table">
                            <md-list-item dir-paginate="alert in tab.data.content|itemsPerPage:vm.paginationData.rowsPerPage" pagination-id="vm.paginationId(tab)" total-items="tab.data.total"
                                          current-page="tab.currentPage">
                                <div layout="row" layout-fill>
                                    <div flex="10" layout="column" style="overflow:hidden; text-overflow:ellipsis;" class="item-column  md-list-item-text pointer" ng-click="vm.alertDetails($event,alert)">
                                        <span class="item-title">
                                            {{alert.level}}
                                        </span>
                                        <span class="column-title column-title-bottom">Level</span>
                                    </div>

                                    <div flex="20" layout="column" hide show-gt-xs show-lg show-xl show-sm show-md class="item-column  md-list-item-text pointer" ng-click="vm.alertDetails($event,alert)">
                                        <span class="item-title">{{alert.state }}</span>
                                        <span class="column-title column-title-bottom">State</span>
                                    </div>
                                    <div flex="10" layout="column" hide show-gt-xs show-lg show-xl show-sm show-md class="item-column  md-list-item-text pointer" ng-click="vm.alertDetails($event,alert)">
                                        <span class="item-title">{{alert.typeDisplay }}</span>
                                        <span class="column-title column-title-bottom">Type</span>
                                    </div>
                                    <div flex="5" layout="column" hide show-gt-xs show-lg show-xl show-sm show-md class="item-column  md-list-item-text pointer" ng-click="vm.alertDetails($event,alert)" ng-if="vm.showCleared">
                                        <ng-md-icon class="primary-color-1" icon="check_box" ng-if="alert.cleared"></ng-md-icon>
                                        <ng-md-icon class="primary-color-1" icon="check_box_outline_blank" ng-if="!alert.cleared"></ng-md-icon>
                                        <span class="column-title column-title-bottom">Cleared</span>
                                    </div>

                                    <div flex="20" layout="column" hide show-gt-xs show-lg show-xl show-sm show-md class="item-column  md-list-item-text pointer" ng-click="vm.alertDetails($event,alert)">
                                        <span class="item-title">{{alert.createdTime | date: 'MMM d, yyyy HH:mm:ss'}}</span>
                                        <span class="column-title column-title-bottom">Start Time</span>
                                    </div>

                                    <div flex="35" layout="column" hide show-gt-xs show-lg show-xl show-sm show-md class="item-column  md-list-item-text pointer" ng-click="vm.alertDetails($event,alert)">
                                        <span class="item-title">{{alert.description }}</span>
                                        <span class="column-title column-title-bottom">Description</span>
                                    </div>

                                </div>
                                <md-divider ng-if="!$last"></md-divider>

                            </md-list-item>
                            <md-list-item ng-show="vm.showProgress == false && tab.data.content.length == 0" class="push-left">
                                No results found
                            </md-list-item>
                            <md-divider></md-divider>
                        </md-list>
                    </div>

                    <div ng-show="vm.viewType == 'table'">
                        <md-table-container>
                            <table md-table md-progress="vm.deferred.promise">
                                <thead md-head md-order="vm.paginationData.sort" md-on-reorder="vm.onOrderChange">
                                    <tr md-row>
                                        <th md-column  md-order-by="level" name="Level">Level</th>
                                        <th md-column  md-order-by="state" name="State">State</th>
                                        <th md-column  md-order-by="type" name="Type">Type</th>
                                        <th md-column name="Cleared" ng-if="vm.showCleared">Cleared</th>
                                        <th md-column name="Start Time" md-order-by="startTime" hide show-gt-sm>Start Time</th>
                                        <th md-column name="Description">Description</th>
                                    </tr>
                                </thead>
                                <tbody md-body>
                                    <tr md-row ng-repeat="alert in tab.data.content" ng-click="vm.alertDetails($event,alert)">
                                        <td md-cell>{{alert.level}}</td>
                                        <td md-cell>{{alert.state}}</td>
                                        <td md-cell>{{alert.typeDisplay}}</td>
                                        <td md-cell ng-if="vm.showCleared">
                                            <ng-md-icon class="primary-color-1" icon="check_box" ng-if="alert.cleared"></ng-md-icon>
                                            <ng-md-icon class="primary-color-1" icon="check_box_outline_blank" ng-if="!alert.cleared"></ng-md-icon>
                                        </td>
                                        <td md-cell hide show-gt-sm>{{alert.createdTime | date:'MMM d, yyyy HH:mm:ss'}}</td>
                                        <td md-cell>{{alert.description}}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </md-table-container>
                        <div ng-if="vm.showProgress == false && tab.data.content.length == 0" layout="column" layout-align="center center">
                            No results found
                        </div>
                        <md-divider></md-divider>
                    </div>

                    <dir-pagination-controls pagination-id="vm.paginationId(tab)"
                                             auto-hide="false"
                                             max-size="5"
                                             direction-links="true"
                                             boundary-links="false"
                                             template-url="js/ops-mgr/alerts/alerts-pagination.tpl.html"
                                             on-page-change="vm.onPaginationChange(newPageNumber)"
                                             label='{{"views.all-page.Rows_per_page" | translate}}'
                                             rows-per-page="vm.paginationData.rowsPerPage"
                                             rows-per-page-options="vm.paginationData.rowsPerPageOptions"
                                             class="pagination-row">
                    </dir-pagination-controls>
                </md-tab-body>
            </md-tab>
        </md-tabs>
    </body-section>
</card-layout>
